﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Visitor;

namespace ASTClass
{
    class NumberAST : TerminalAST
    {
        public NumberAST() : base() { name = "Number"; }
        public NumberAST(AST parent) : base(parent) { name = "Number"; }

        public override AST Clone()
        {
            NumberAST ast = new NumberAST();
            ast.operators = operators;
            foreach (AST c in children)
                ast.children.Add(c.Clone());

            return ast;
        }

        #region Visitor pattern

        public override void Accept(IVisitor visitor)
        {
            visitor.Visit(this);
        }

        #endregion Visitor pattern

        public override void CodeGen(Taste.SymbolTable symTab, Taste.CodeFileGen cfg)
        {
            cfg.AddCommand("subu", "$sp, $sp, 4");
            cfg.AddCommand("li", "$t1, " + this.Value);
            cfg.AddCommand("sw", "$t1, 0($sp)");
        }
    }
}
